
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>redis主哨兵的选举，之前的主恢复了怎么办？ - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>redis主哨兵的选举，之前的主恢复了怎么办？ - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在Redis主-哨兵架构中，一个发生故障后恢复的原主节点，会如何处理自己的角色和状态？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">如果恢复的原主节点发现自己已经不是集群的主节点，它会自动成为当前新主节点的从节点，并将自己配置为从节点，然后开始从新的主节点同步数据。</div>
          </div>
          <div class="card-source">来源: 2. 恢复主节点的状态</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">流程</div>
          <div class="card-question">一个从故障中恢复的原Redis主节点，最初是如何获取集群最新状态信息的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">流程</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">恢复的原主节点会首先尝试连接到哨兵（Sentinel），并通过哨兵获取当前集群的状态信息，包括当前的主节点信息和从节点信息。</div>
          </div>
          <div class="card-source">来源: 1. 主节点恢复后的初步处理</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">为了防止数据不一致，当恢复的原主节点发现存在数据丢失时，系统会采取什么措施？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">如果存在数据丢失，恢复的原主节点会在成为从节点时，从新的主节点进行全量同步（full synchronization），以确保数据的一致性。</div>
          </div>
          <div class="card-source">来源: 3. 防止数据不一致</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">角色</div>
          <div class="card-question">在故障转移后，哨兵（Sentinel）是如何处理一个恢复上线的老主节点的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">角色</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">哨兵会自动检测到恢复的主节点，并将其自动配置为新主节点的从节点。哨兵还会确保，如果该恢复节点的数据较旧或不符合一致性要求，它将不会被提升为新的主节点。</div>
          </div>
          <div class="card-source">来源: 4. 故障转移后的处理</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">配置</div>
          <div class="card-question">文档中提到了哪两个关键配置项，可以用于在主节点故障时帮助管理数据一致性？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">配置</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">文档中提到了 `min-slaves-to-write` 和 `min-slaves-max-lag` 这两个配置项，它们可以确保主节点在进行写操作时，有足够数量的从节点可用并保持同步。</div>
          </div>
          <div class="card-source">来源: 5. 配置与调优</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">当一个恢复的原主节点需要转变为从节点时，它具体会执行哪个命令？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">它会执行 `SLAVEOF <new-master-ip> <new-master-port>` 命令，将自己设置为新主节点的从节点。</div>
          </div>
          <div class="card-source">来源: 2. 恢复主节点的状态</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
